<?php

/**
 * bay3Mailer
 *
 * @package    bay3
 * @subpackage mailer
 * @author     Redouane
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class bay3Mailer
{
    
	/**
	 * 
	 */
	static public function initMailer(){
		$contextInstance = sfContext::getInstance();
		$contextInstance->getConfiguration()->loadHelpers('Partial');
	}
	
	  
	/**
    * 
    * @param array $to adresses email destinataire : adresse simple, liste séparée par des virgule ou tableau
    * @param string $subject
    * @param string $body
    * @param string $from
    * @param string $file pathfile ud fichier a attacher
    */
    static public function sendEmail($to, $subject, $body, $from = 'no-reply@bay3wachira.com', $file = null){
		if(!is_array($to)) 
			$to = explode(',', $to);  
		
		$mailer  = sfContext::getInstance()->getMailer();
        $message = Swift_Message::newInstance()
        			->setFrom($from)
        			->setTo($to)
          			->setSubject($subject)
          			->setBody($body)
		    		->setContentType("text/html");
        if(!is_null($file)) {
            $message->attach(Swift_Attachment::fromPath($file));
        }
        
        $mailer->send($message);
   }
   
   /**
    * 
    */
  static public function sendMail($to, $subject, $body, $from = 'no-reply@bay3wachira.com',$fullname = ''){
  	 $headers ='From: "'.$fullname.'"<noresponse@bay3.com>' . "\n"; 
     $headers .='Content-Type: text/html; charset="UTF-8"'."\n"; 
     $headers .='Content-Transfer-Encoding: 8bit'; 

  	 mail($to, $subject, $body, $headers);
  }
  
}
